<?php

namespace app\model\system;

use app\model\BaseModel;

/**
 *
 */
class SysDict extends BaseModel
{
  
  /**
   * The table associated with the model.
   *
   * @var string
   */
  protected $table = "sys_dict";


  public function dictItems()
  {
    return $this->hasMany(SysDictItem::class, 'dict_code', 'dict_code');
  }

  public function getItems(): array
  {
    $items = [];
    if ($this->dictItems) {
      foreach ($this->dictItems as $item) {
        $items[] = $item->getFormArray();
      }
    }
    return $items;
  }

  public function getFormArray(): array
  {
    return [
      "dictCode" => $this->dictCode,
      "id" => $this->id,
      "name" => $this->name,
      "remark" => $this->remark,
      "status" => $this->status,
    ];
  }

  public function toArray(array $merges = []): array
  {
    $modeArray = $this->getFormArray() + [
      "items" => $this->getItems()
    ];
    return $this->merge($modeArray, $merges);
  }
}
